#include <iostream>
using namespace std;

class Base{
public:
    // 无参构造函数
    Base(){

    }
    // 构造函数
    Base(const long base)
    :_base(base)
    {  }
    //虚函数，会使得申请的空间会多8字节
    virtual
    void display(){
        cout << "Base::display()" << endl;
    }

private:
    long _base;
};

class Derived : public Base{
public:
    // 无参构造函数
    Derived(){

    }

    // 构造函数
    Derived(const long derived,const long base)
    :_derived(derived)
    ,Base(base)
    {  }

    void display(){
        cout << "Derived::display()" << endl;
    }

private:
    long _derived;
};

void print(Base * pbase){
    pbase->display();
}

void test(){
    // 不加虚函数测试
    Base base;
    Derived derived;
    Base * pbase = &derived;
    pbase->display();
    cout << sizeof(Base) << endl;
    cout << sizeof(Derived) << endl;
}

void test1(){
    // 添加虚函数测试
    Base base(10);
    Derived dd(1,2);

    cout << endl;
    print(&base);
    print(&dd);
    cout << sizeof(Base) << endl;
    cout << sizeof(Derived) << endl;
}
int main(int atgc, char * argv[])
{
    test1();
    return 0;
}

